#include <iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;

int main() {
	int N;
	cin >> N;
	map<int, int> map;
	for (int i = 0; i < N; i++) {
		int a, b;
		cin >> a >> b;
		map[a] = map[a] + b;
	}
	for (auto& item : map) {
		cout << item.first << " " << item.second << endl;
	}
}
